package com.zj;

import com.zj.bean.UserInfo;
import com.zj.dao.UserDao;
import com.zj.sqlSession.SqlSession;
import com.zj.sqlSession.SqlSessionFactory;
import com.zj.utils.Resources;
import com.zj.utils.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        Reader reader = null;
        try {
            reader = Resources.getResourceAsReader("mybatis.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        //使用构建者模式
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        //用工厂模式创建session
        SqlSession session = sqlSessionFactory.openSession();
        UserDao mapper = session.getMapper(UserDao.class);
        UserInfo user=mapper.queryUserByID(70);
        System.out.println(user);
//        UserInfo userInfo=new UserInfo();
//        userInfo.setAddress("济宁市8号");
//        userInfo.setName("jenny5");
//        int a=mapper.updateNameAndAdd(userInfo,83);
//        session.commit();
//        System.out.println(a);
    }
}
